//
//  BaseNaviVC.m
//  TrainFinder3
//
//  Created by 饶首建 on 17/2/28.
//  Copyright © 2017年 com.ikamobile.trainfinder3. All rights reserved.
//

#import "BaseNaviVC.h"

@interface BaseNaviVC () <UINavigationControllerDelegate>

@property (nonatomic, weak) id popDelegate;

@end

@implementation BaseNaviVC

- (void)viewDidLoad {
    [super viewDidLoad];
    _popDelegate = self.interactivePopGestureRecognizer.delegate;
    self.delegate = self;
    
    [self setNaviBar];
}

- (void)setNaviBar{
    UINavigationBar *navigationBar = [UINavigationBar appearance];
    navigationBar.tintColor = [UIColor whiteColor];//THEMCOLOR;
    navigationBar.translucent = NO;
    [navigationBar setBackgroundImage:[UIImage imageWithColor:[THEMCOLOR colorWithAlphaComponent:1.f] size:CGSizeMake(SWidth(), NavigationBarHeight)] forBarMetrics:UIBarMetricsDefault];
    navigationBar.titleTextAttributes = @{NSFontAttributeName:SystemBoldFont(18.f), NSForegroundColorAttributeName:[UIColor whiteColor]};
}

-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (viewController == self.viewControllers[0]) {
        self.interactivePopGestureRecognizer.delegate = _popDelegate;
    }else{
        self.interactivePopGestureRecognizer.delegate = nil;
    }
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
    
    UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(backBarButtonItemAction)];
    viewController.navigationItem.backBarButtonItem = backBarButtonItem;
    
//    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"trainfinder_date_dlg_pre_month_btn_bg"] style:UIBarButtonItemStylePlain target:nil action:nil];
//    [[UINavigationBar appearance] setBackIndicatorImage:[[UIImage alloc]init]];
//    [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[[UIImage alloc] init]];
//    viewController.navigationItem.backBarButtonItem = item;
    
}

- (void)backBarButtonItemAction{
    [self popViewControllerAnimated:YES];
}

- (BOOL)prefersStatusBarHidden{
    return NO;
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
